<?php

/**
 * XHTML_Img, xhtml_lib
 * 
 * This file contains the source code for the XHTML_Img class.
 * @author Fernando Jimenez Mocobono <fjmcool@gmail.com>
 * @version 0.1
 * @package xhtml_lib
 */

include_once "XHTML_Common_Element.php";
include_once "XHTML__Special.php";
include_once "XHTML_Inline.php";


/**
 * The XHTML_Img class is a handler for the img xhtml-strict tag as a part
 * of a xhtml-strict php-handler implementation.
 */
class XHTML_Img extends XHTML_Common_Element implements XHTML__Special {
    
    // xhtml attributes
    
    /**
     * URI of the image to display.
     * 
     * @var string
     */
    protected $src;
    
    /**
     * Short description of the image.
     *
     * @var string
     */
    protected $alt;
    
    /**
     * URI to a document that contains a long description of the image.
     *
     * @var string
     */
    protected $longDesc;
    
    /**
     * Height of the image. (nn for pixels or nn% for percentage).
     *
     * @var mixed
     */
    protected $height;
    
    /**
     * Width of the image. (nn for pixels or nn% for percentage).
     *
     * @var mixed
     */
    protected $width;
    
    /**
     * URI that defines the image as a client-side image map.
     * 
     * @var string
     */
    protected $useMap;
    
    /**
     * Defines the image as a server-side image map.
     *
     * @var boolean
     */
    protected $isMap;
    
    
    // Methods
    
    /**
     * Constructs a XHTML_Img object.
     */
    function __construct()
    {
    }
    
    /**
     * Sets the URI of the image to display.
     *
     * @param string $src
     */
    function setSrc($src)
    {
        $this->src = $src;
    }
    
    /**
     * Gets the URI of the image to display.
     *
     * @return string
     */
    function getSrc()
    {
        return $this->src;
    }
    
    /**
     * Sets a short description of the image.
     *
     * @param string $alt
     */
    function setAlt($alt)
    {
        $this->alt = $alt;
    }
    
    /**
     * Gets the short description of the image.
     *
     * @return string
     */
    function getAlt()
    {
        return $this->alt;
    }
    
    /**
     * Sets the URI to a document that contains a long description of the image.
     * 
     * @param string $longDesc
     */
    function setLongDesc($longDesc)
    {
        $this->longDesc = $longDesc;
    }
    
    /**
     * Gets the URI to a document that contains a long description of the image.
     *
     * @return string
     */
    function getLongDesc()
    {
        return $this->longDesc;
    }
    
    /**
     * Sets the height of the image. (nn for pixels or nn% for percentage).
     * 
     * @param mixed $height
     */
    function setHeight($height)
    {
        $this->height = $height;
    }
    
    /**
     * Gets the height of the image. (nn for pixels or nn% for percentage).
     *
     * @return mixed
     */
    function getHeight()
    {
        return $this->height;
    }
    
    /**
     * Sets the width of the image. (nn for pixels or nn% for percentage).
     * 
     * @param mixed $width
     */
    function setWidth($width)
    {
        $this->width = $width;
    }
    
    /**
     * Gets the width of the image. (nn for pixels or nn% for percentage).
     * 
     * @return mixed
     */
    function getWidth()
    {
        return $this->width;
    }
    
    /**
     * Sets the URI that defines the image as a client-side image map.
     *
     * @param string $useMap
     */
    function setUseMap($useMap)
    {
        $this->useMap = $useMap;
    }
    
    /**
     * Gets the URI that defines the image as a client-side image map.
     *
     * @return string
     */
    function getUseMap()
    {
        return $this->useMap;
    }
    
    /**
     * Defines the image as a server-side image map.
     *
     * @param boolean $isMap
     */
    function setIsMap($isMap)
    {
        $this->isMap = $isMap;
    }
    
    /**
     * Checks if the image is a server-side image map.
     *
     * @return boolean
     */
    function isIsMap()
    {
        return $this->isMap;
    }


    // Overriding the toString method for a proper implementation.
    
    /**
    * Returns the string representation for echoing the class atributes.
    *
    * @return string
    */
    function toString()
    {
        $auxString = "<img".parent::toString();
        
        /*
         * Additions of the object own attributes to the return string.
         */
        
        if (isset($this->src)) {
            $auxString = $auxString."src=\"".$this->src."\" ";
        }
        
        if (isset($this->alt)) {
            $auxString = $auxString."alt=\"".$this->alt."\" ";
        }
        
        if (isset($this->longDesc)) {
            $auxString = $auxString."longDesc=\"".$this->longDesc."\" ";
        }
        
        if (isset($this->height)) {
            $auxString = $auxString."height=\"".$this->height."\" ";
        }
        
        if (isset($this->width)) {
            $auxString = $auxString."width=\"".$this->width."\" ";
        }
        
        if (isset($this->useMap)) {
            $auxString = $auxString."usemap=\"".$this->useMap."\" ";
        }
        
        if ($this->isMap) {
            $auxString = $auxString."ismap=\"ismap\" ";
        }
        
        $auxString = $auxString."/>\n";
        
        return $auxString;
    }
    
}

?>